package com.smartTerminal.perMatters.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smartTerminal.perMatters.service.PhoneValiCodeService;

/**
 * 根据手机号码发送验证码并将验证码返回
 * @author wantao
 * @Date 2018年1月11日
 *
 */
@Controller
@RequestMapping("/PhoneValiCodeController")
public class PhoneValiCodeController {

	@Autowired
	private PhoneValiCodeService phoneValiCodeService;
	
	/**
	 * 获取验证码
	 * @param phone
	 * @return
	 */
	@RequestMapping("getPhoneValiCode")
	@ResponseBody
	public String getPhoneValiCode(String phone,HttpServletRequest request){
		return phoneValiCodeService.getPhoneValiCode(phone);
	}
	
	/**
	 * 校验手机号验证码是否正确
	 * @param phone 手机号
	 * @param phoneCode 输入的验证码
	 * @param request
	 * @return
	 */
	@RequestMapping("valiPhoneCode")
	public String valiPhoneCode(String phone,String phoneCode,HttpServletRequest request){
		HttpSession session = request.getSession();
		String vali_code = (String) session.getAttribute("phone");
		String view = null;
		try {
			view =  phoneValiCodeService.valiPhoneCode(phone, phoneCode, vali_code);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return view;
	}
	
}
